home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13777 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.4 KB  |  111 lines

  1. Path: ix.netcom.com!chi-il9-08
  2. From: stefmit@ix.netcom.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Working through C++ - some help needed
  5. Date: 27 Mar 1996 04:50:33 GMT
  6. Organization: Netcom
  7. Message-ID: <4jahep$b34@dfw-ixnews2.ix.netcom.com>
  8. References: <3158EDE7.2C27@intercom.com>
  9. NNTP-Posting-Host: chi-il9-08.ix.netcom.com
  10. X-NETCOM-Date: Tue Mar 26 10:50:33 PM CST 1996
  11. X-Newsreader: News Xpress Version 1.0 Beta #4
  12.  
  13. In article <3158EDE7.2C27@intercom.com>, access <access@intercom.com> wrote:
  14. >Working my way through the "forest" of C++, I try to work on an exercise 
  15. >that is more like invented, than a proven workable problem - but I 
  16. >thought of being of help in understanding different concepts in C++. I am 
  17. >trying to build the followings (based on classes, rather than one 
  18. >single lenghty algorithm):
  19. >- An array list (having the regular functions, like the ones shown 
  20. >everywhere in the books: get, put, moveto, gotostart, gotoend, etc.), 
  21. >which will contain a different queue in each of its elements, queues 
  22. >being distinguished by a number (with pop and push functions, at least) 
  23. >which queue will contain nodes (... remember the Russian dols :-) ...), 
  24. >and each node will contain a couple of the most significant elements of 
  25. >C++ (a char, an int, a string, for example).
  26. >Now, being said the above, I don't know how to start building and how to 
  27. >access the elements of each node (I don't even know if it is possible) 
  28. >either by user input or from a file. What I try actually would be 
  29. >something like: given an element with the int as the array element where 
  30. >its queue is to be placed, how do I actually put it there using the 
  31. >normal messages such constructions would come with (like: read the whole 
  32. >element from a file as a string which has the data separated by blanks - 
  33. >int, char and string, then taking the int and deciding what element in 
  34. >the array it is going to go into, then taking the char and the string and 
  35. >building the actual element and attaching it to the queue in the decided 
  36. >array element). Did anybody make any sense out of this? If the answer is 
  37. >YES, would any kind soul enlighten me on whether this would be possible 
  38. >to build, and actually how to manipulate the messages of the different 
  39. >classes I see being built (class array_list, class My_queue and class 
  40. >My_queue_node) to put/remove the elements?
  41. >Thanks a lot to whoever had the patience to read through this lenghty and 
  42. >senseless message, and mostly to whoever would care to answer me if this 
  43. >is "mission impossible".
  44. >
  45. >Sleepless_C++
  46.  
  47. That's an interesting subject (for a beginner, like myself). I will "bite":
  48.     
  49. What about the following classes:
  50.  
  51. class My_elem_in_node
  52. {private: int my_number;
  53.       char my_char;
  54.       char *my_strg_ptr;
  55. public:  int get_my_number ();
  56.      char get_my_char();
  57.      char *get_my_strg();
  58.      // a constructor
  59.      // a destructor
  60.      void set_my_number (int &new_number) const;
  61.      void set_my_char (char &new_char) const;
  62.      void *set_my_strg (char *new_strg); }
  63.  
  64. template <my_type_above>
  65. class My_queue_node
  66. {private: My_queue_node (const my_type_above &new_element, My_queue_node 
  67. *next_ptr)
  68. public: my_type_above node_element;
  69.     My_queue_node *next;
  70. friend class My_queue <my_type_above>; }
  71.  
  72. template <class my_type_above>
  73. class My_queue
  74. {public: My_queue();
  75.      ~My_queue();
  76.      void enqueue (const my_type_above &new_node)
  77.      my_type_above dequeue();
  78.      // others, like clear(), isempty(), isfull(), display(), etc.
  79. private: My_queue_node <my_type_above> *head, *tail; }
  80.  
  81. template <class my_type_above>
  82. class my_array
  83. {public: my_array (int max_nb_of_elements = 10);
  84.      ~my_array();
  85.      void insert (const my_type_above &new_array_element);
  86.      void remove ();
  87.      // and others (perhaps a clear (), is_empty(), is_full(), etc.)
  88. private: int max_array_size;
  89.      int size_array;
  90.        int cursor; // to go through array
  91.      my_type_above *array_element; }
  92.  
  93. class strg_manipulator // for whatever string you're getting from a file/user
  94. {private: char *strg_content;
  95. public:   strg_manipulator (char *string_in = 0);
  96.       ~strg_manipulator ();
  97.       char *get_user_strg ();
  98.       void *set_user_strg (char *string_in); }
  99.  
  100. For sure other classes will fit here, like file I/O processing (read, save), 
  101. etc.
  102. I hope this helps, but definitely doesn't fully answer your question. I told 
  103. you I am a beginner myself :-). Perhaps somebody will care to correct or 
  104. complete me with how to put these pieces together.
  105.  
  106. PS - You might want to check your e-mail address - it bounces back when I try 
  107. to e-mail you.
  108.  
  109. Cheers,
  110. Stefan
  111.